package com.example.deertrip;

import androidx.appcompat.app.AppCompatActivity;

import com.example.deertrip.bean.Tb_HotelReserve;
import com.example.deertrip.database.DBOperate;
import com.example.deertrip.tools_class.UserStateGet;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.SimpleAdapter;
import android.widget.Spinner;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class HotelActivity extends AppCompatActivity{
    private List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();

    private SimpleAdapter simpleAdapter = null;
    private DBOperate dbOperate;
    private String lindate;
    private String loutdate;

    private String Hname;

    public String getlindate(){
        return lindate;
    }

    public void setlindate(String lindate){
        this.lindate=lindate;
    }

    public String getHname(){
        return Hname;
    }

    public void setHname(String Hname){
        this.Hname=Hname;
    }

    public String getloutdate(){
        return loutdate;
    }

    public void setloutdate(String loutdate){
        this.loutdate=loutdate;
    }

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_hotel);


        //酒店信息详情页
        TextView hotelname=findViewById(R.id.honame);
        TextView hotelscore=findViewById(R.id.hoscore);
        TextView hoteladdress=findViewById(R.id.hoaddress);
        ImageView imageView=findViewById(R.id.hoimage);

        Bundle bundle=getIntent().getExtras();
        if(bundle!=null){
            hotelname.setText((String)bundle.get("HotelName"));
            hotelscore.setText((String)bundle.get("HotelScore"));
            hoteladdress.setText((String)bundle.get("HotelAddress"));
            setHname((String)bundle.get("HotelName"));//存入Hname，传给按钮携带bundle
            byte[] in=getIntent().getByteArrayExtra("HotelImage");
            Bitmap bitmap= BitmapFactory.decodeByteArray(in,0,in.length);
            imageView.setImageBitmap(bitmap);
        }

        //spinner_in
        Spinner spinner_in=findViewById(R.id.spindatein);
        spinner_in.setSelection(0);		//初始化，默认选择列表中第0个元素
        spinner_in.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
                // TODO
                if (pos==1){
                    setlindate("2022-7-2");
                }
                else if(pos==2){
                    setlindate("2022-7-3");
                }
                else if(pos==3){
                    setlindate("2022-7-4");
                }
                else if(pos==4){
                    setlindate("2022-7-5");
                }
                else if(pos==5){
                    setlindate("2022-7-6");
                }
                else if(pos==6){
                    setlindate("2022-7-7");
                }
                else{
                    setlindate("2022-7-1");
                }
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {
                setlindate("2022-7-1");
                // TODO
            }

        });

        //spinner_out
        Spinner spinner_out=findViewById(R.id.spindateout);
        spinner_out.setSelection(0);		//初始化，默认选择列表中第0个元素
        spinner_out.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
                // TODO
                if (pos==1){
                    setloutdate("2022-7-3");
                }
                else if(pos==2){
                    setloutdate("2022-7-4");
                }
                else if(pos==3){
                    setloutdate("2022-7-5");
                }
                else if(pos==4){
                    setloutdate("2022-7-6");
                }
                else if(pos==5){
                    setloutdate("2022-7-7");
                }
                else if(pos==6){
                    setloutdate("2022-7-8");
                }
                else{
                    setloutdate("2022-7-2");
                }
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {
                setloutdate("2022-7-2");
                // TODO
            }

        });

        //购买按钮
        Button button_buy1;
        Button button_buy2;
        Button button_buy3;
        button_buy1=(Button) findViewById(R.id.buy1);
        button_buy2=(Button) findViewById(R.id.buy2);
        button_buy3=(Button) findViewById(R.id.buy3);

        button_buy1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                UserStateGet usg=new UserStateGet();
                usg.vlidate(HotelActivity.this);
                HashMap<String, Object> items=new HashMap<String, Object>();
                Bundle bundle=new Bundle();
                bundle.putString("HotelName",getHname());
                bundle.putString("RoomNumber","101");
                bundle.putString("HotelOrderPrice","113");
                bundle.putString("lindate",getlindate());
                bundle.putString("loutdate",getloutdate());
                bundle.putString("RoomType","大床房");
                if(usg.canbuy == 0)
                {Intent intent=new Intent(HotelActivity.this, activity_pay_Activity.class);
                intent.putExtras(bundle);
                startActivity(intent);}
            }
        });
        button_buy2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                UserStateGet usg=new UserStateGet();
                usg.vlidate(HotelActivity.this);
                HashMap<String, Object> items=new HashMap<String, Object>();
                Bundle bundle=new Bundle();
                bundle.putString("HotelName",getHname());
                bundle.putString("RoomNumber","101");
                bundle.putString("HotelOrderPrice","105");
                bundle.putString("lindate",getlindate());
                bundle.putString("loutdate",getloutdate());
                bundle.putString("RoomType","双人房");
                if(usg.canbuy == 0)
                {Intent intent=new Intent(HotelActivity.this, activity_pay_Activity.class);
                    intent.putExtras(bundle);
                    startActivity(intent);}
            }
        });
        button_buy3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                UserStateGet usg=new UserStateGet();
                usg.vlidate(HotelActivity.this);
                HashMap<String, Object> items=new HashMap<String, Object>();
                Bundle bundle=new Bundle();
                bundle.putString("HotelName",getHname());
                bundle.putString("RoomNumber","101");
                bundle.putString("HotelOrderPrice","80");
                bundle.putString("lindate",getlindate());
                bundle.putString("loutdate",getloutdate());
                bundle.putString("RoomType","单人房");
                if(usg.canbuy == 0)
                {Intent intent=new Intent(HotelActivity.this, activity_pay_Activity.class);
                    intent.putExtras(bundle);
                    startActivity(intent);}
            }
        });




    }

}

